{% extends "base.html" %}


{% block  title %}工具{% endblock %}

{% block page-content %}



    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>工具</h2>
            <ol class="breadcrumb">
                <li>
                    <a href="/index.html">主页</a>
                </li>
                <li>
                    <a>工具</a>
                </li>
                <li class="active">
                    <strong>工具</strong>
                </li>
            </ol>
        </div>
        <div class="col-lg-2">

        </div>
    </div>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>工具</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                                <li><a href="#">选项 1</a>
                                </li>
                                <li><a href="#">选项 2</a>
                                </li>
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">

                          <div class="table-responsive">

                            <a href="{% url    'tasks:tools_add' %}" class="btn btn-primary  ">
                                添加</a>

                            <a class="btn btn-danger  asset_all_del"
                              >批量删除
                            </a>





                            <form id="del_form_tools_bulk" class="form-horizontal  ">

                                <table class="table table-striped table-bordered table-hover dataTables-example">
                                    <thead>
                                    <tr>
                                        <th width="20"><input type="checkbox" id="CheckedAll"></th>
                                        <th>名称</th>
                                        <th>脚本类型</th>
                                        <th>工具说明</th>
                                        <th>更新时间</th>
                                        <th>动作{{ error_performance }}</th>
                                    </tr>
                                    </thead>
                                    <tbody>

                                    {% for   row   in   tools %}

                                        <tr class="gradeA" id="{{ row.id }}">
                                            <td><input  type="checkbox"   value="{{ row.id }}"   name="id"></td>
                                            <td class="center">{{ row.name }}</td>
                                            <td class="center">{% ifequal  row.tool_run_type  0 %} shell{% endifequal  %} {% ifequal  row.tool_run_type  1 %} python {% endifequal  %}  {% ifequal row.tool_run_type  2 %}  yml {%  endifequal%}  </td>
                                            <td class="center">{{ row.comment }}</td>
                                            <td class="center">{{ row.utime }}</td>

                                            <td>
                                                <a class="btn btn-primary  btn-xs "
                                                   href="{% url  "tasks:tools_script_get"   row.id   %}">执行</a>

                                                <a class="btn btn-primary  btn-xs "
                                                   href="{% url  "tasks:tools_update"   row.id   %}">编辑</a>
                                                <a class="btn btn-danger  btn-xs  tools_del"
                                                      >删除
                                                </a>
                                            </td>
                                        </tr>
                                    {% endfor %}

                                    </tbody>

                                </table>


                            </form>


                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>


    {% block footer-js %}
      <script type="text/JavaScript">
    $.ajaxSetup({headers: {"X-CSRFToken": '{{ csrf_token }}'}});
</script>

        <script>
            $(function () {
  $(document).on('click','.tools_del',function () {


                    var   id = $(this).parent().parent().attr('id');


                   swal({

                        title: "你确定删除",
                        text: "你将无法恢复",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",

                        closeOnConfirm: false
                    }, function () {
                    $.ajax({
                        url: "/tasks/tools-del.html",
                        type: 'POST',
                       data: {'nid': id},
                            success: function (data) {
                                var obj = JSON.parse(data);
                                if (obj.status) {
                                    swal({title: "删除", text: "已成功删除", type: "success"}, function () {
                                        window.location.reload();
                                    })
                                } else {
                                    swal("错误", "删除" + "[ " + obj.error + " ]" + "遇到错误", "error");
                                }
                            }
                        })
                    });
                });

  $(document).on('click','.asset_all_del',function () {




                       swal({

                        title: "你确定删除",
                        text: "你将无法恢复",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",

                        closeOnConfirm: false
                    }, function () {
                    $.ajax({
                        url: "/tasks/tools-bulk-del.html",
                        type: 'POST',
                        data: $('#del_form_tools_bulk').serialize(),
                         success: function (data) {
                                var obj = JSON.parse(data);
                                if (obj.status) {
                                    swal({title: "删除", text: "已成功删除", type: "success"}, function () {
                                        window.location.reload();
                                    })
                                } else {
                                    swal("错误", "删除" + "[ " + obj.error + " ]" + "遇到错误", "error");
                                }
                            }
                        })
                    });
                });
 });

</script>


{% endblock %}

{% endblock %}